﻿using NAnt.Core.Attributes;
using NAnt.Core;
using NAnt.Core.Util;
using System.Xml;
using System;
using NAnt.SVN.Util;
using System.IO;

namespace NAnt.SVN.Tasks
{
    /// <summary>
    /// Use this class to run the SVN info command
    /// You can run this tasc with the svnexport tag in NAnt.
    /// $Id$
    /// </summary>
    [TaskName("svnexport")]
    sealed public class Export : SVNTask
    {
        #region Private Fields

        DirectoryInfo todirectory;
        string fromurl = string.Empty;
        bool force = false;

        #endregion

        #region Public fields

        /// <summary>
        /// The directory to export to.
        /// </summary>
        [TaskAttribute("todir",Required=true)]
        public DirectoryInfo ToDirectory
        {
            get { return todirectory; }
            set { todirectory = value; }
        }

        /// <summary>
        /// Url to copy from, if omitted, the current directory is taken
        /// </summary>
        [TaskAttribute("fromurl",Required=false)]
        [StringValidator(AllowEmpty=true)]
        public string URL
        {
            get { return fromurl; }
            set { fromurl = value; }
        }

        /// <summary>
        /// Force it or not.
        /// </summary>
        [TaskAttribute("force", Required = false)]
        [BooleanValidator()]
        public bool Force
        {
            get { return force; }
            set { force = value; }
        }

        #endregion

        /// <summary>
        /// Initalize the task
        /// </summary>
        protected override void InitializeSVNTask()
        {
            //Set the command
            Command = SVNCommands.EXPORT;
            Options.Add(quote(string.IsNullOrEmpty(URL) ? Project.BaseDirectory : URL));
            Options.Add(quote(ToDirectory.FullName));
            if (Force) Options.Add(SVNFlags.FORCE);
        }
    }
}
